package io.renren.modules.sys.customer.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.sys.controller.AbstractController;
import io.renren.modules.sys.customer.entity.BtCustomerBaseEntity;
import io.renren.modules.sys.customer.entity.BtCustomerProBaseinfoEntity;
import io.renren.modules.sys.customer.service.BtCategroyManageService;
import io.renren.modules.sys.customer.service.BtCustomerBaseService;
import io.renren.modules.sys.customer.service.BtCustomerProBaseinfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author goudandan
 * @email resjz1@163.com
 * @date 2018-09-18 11:43:43
 */
@RestController
@RequestMapping("sys/btcustomerprobaseinfo")
public class BtCustomerProBaseinfoController extends AbstractController {
    @Autowired
    private BtCustomerProBaseinfoService btCustomerProBaseinfoService;
    @Autowired
    private BtCustomerBaseService btCustomerBaseService;
    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("sys:btcustomerprobaseinfo:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = btCustomerProBaseinfoService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
   // @RequiresPermissions("sys:btcustomerprobaseinfo:info")
    public R info(@PathVariable("id") Long id){
        BtCustomerProBaseinfoEntity btCustomerProBaseinfo = btCustomerProBaseinfoService.selectById(id);

        return R.ok().put("btCustomerProBaseinfo", btCustomerProBaseinfo);
    }
    @Autowired
    private BtCategroyManageService btCategroyManageService;
    /**
     * 保存
     */
    @RequestMapping("/save")
   // @RequiresPermissions("sys:btcustomerprobaseinfo:save")
    public R save(@RequestBody BtCustomerProBaseinfoEntity btCustomerProBaseinfo){
        Long uid = getUserId();
        if(uid.equals(0)){
            return R.error("非法用户！！");
        }
        BtCustomerBaseEntity btCustomerBase = btCustomerBaseService.SelectOneByUid(uid);
        btCustomerProBaseinfo.setCustId(btCustomerBase.getId());
        btCustomerProBaseinfo.setCatagId(Long.valueOf(btCategroyManageService.selectById(btCustomerProBaseinfo.getZflId()).getCatatype()));
        Long pkey = btCustomerProBaseinfoService.insertOneBackprimkey(btCustomerProBaseinfo);
        return R.ok().put("pkey",pkey);
    }
    @RequestMapping("/saveparam")
    // @RequiresPermissions("sys:btcustomerprobaseinfo:save")
    public R saveparam(@RequestBody BtCustomerProBaseinfoEntity btCustomerProBaseinfo){
        if(btCustomerProBaseinfo.getId()==null){
            R.error("请先填写基本信息并交");
        }
        BtCustomerProBaseinfoEntity oldbean = btCustomerProBaseinfoService.selectById(btCustomerProBaseinfo.getId());
        oldbean.setKcts(btCustomerProBaseinfo.getKcts());
        oldbean.setKcjg(btCustomerProBaseinfo.getKcjg());
        oldbean.setOutline(btCustomerProBaseinfo.getOutline());

        btCustomerProBaseinfoService.insertOrUpdate(oldbean);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:btcustomerprobaseinfo:update")
    public R update(@RequestBody BtCustomerProBaseinfoEntity btCustomerProBaseinfo){
        ValidatorUtils.validateEntity(btCustomerProBaseinfo);
        btCustomerProBaseinfoService.updateAllColumnById(btCustomerProBaseinfo);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:btcustomerprobaseinfo:delete")
    public R delete(@RequestBody Long[] ids){
        btCustomerProBaseinfoService.deleteBatchIds(Arrays.asList(ids));
        return R.ok();
    }

}
